module ApplicationHelper

  def get_hotel_master_name(id)
      ref=HotelMaster.find(id)
      return ref.name
  end

  def hotel_list_name()   #获取小区id，name 下拉框用
      a =HotelInfo.find_by_sql(" SELECT a.id,CONCAT(b.name,'/',a.name) name FROM  hotel_info a,hotel_master b
           where  a.master_id=b.id order by a.master_id desc").map { |aa| [aa.name,aa.id] }
      return a
  end
  
  def get_hotel_info_name(id)
      ref=HotelInfo.find_by_sql("SELECT CONCAT(c.name,'/',b.name) name FROM  record_data a,hotel_info b,hotel_master c
                          where a.hotel_address_id=b.id and b.master_id=c.id and a.hotel_address_id=#{id} LIMIT 1").first
      if ref!=nil
          return ref.name
      else 
          return '数据错误'
      end
  end
  
  def get_pic_url(id,name)
      pic_url="\\uploads\\record_data\\pic\\"+id.to_s+"\\"+name.to_s
      return  pic_url
  end

  def get_tree_root_yh
       first=Section.find_by_sql('SELECT * FROM  sections where id=0').first
       h=[]
       data=Section.find_by_sql("SELECT * FROM  sections where parent_id=#{first.id}")
       for aa in data
           h<<get_tree_child_yh(aa.id)
       end
       return_data={:name=>first.section_name,:appid=>first.id, :open=>true,:children=>h}.to_json
  end

  def get_tree_child_yh(id)
        data=Section.find_by_sql("SELECT * FROM  sections where parent_id=#{id}")
        if data.size<1   #没有子节点了
              first=Section.find_by_sql("SELECT * FROM  sections where id=#{id}").first #找到当前节点
              h={ :name=>first.section_name,:appid=>first.id}
              return h
        else
              first=Section.find_by_sql("SELECT * FROM  sections where id=#{id}").first #找到当前节点
              h=[]
              for aa in data
                h<<get_tree_child_yh(aa.id)
              end
              return_data={ :name=>first.section_name,:appid=>first.id,:open=>true,:children=>h}
              return  return_data
        end
  end

  def ischekck(section_id,community_id)
       ref=SectionCommunity.find_by_sql("SELECT * FROM  section_community
             where community_id =#{community_id} and section_id=#{section_id}").size
       if ref>0 
        return 1
      else
        return 0
      end
  end
  
  def report_data(ref)
      if ref==1
              ref=SectionCommunity.find_by_sql(" SELECT community_id FROM  section_community
        where section_id= #{ session[:section_id] }  ")
                a=[]
                for i in ref 
                   a<<i.community_id
                end
                com_info=a.join(',')
      else
              com_info=session[:section_id]
      end
     return com_info
  end

  def get_report(name,ref)
     data=report_data(ref)
     ref="http://report.mylife114.com/WebReport/ReportServer?reportlet=/tmp/"+name+".cpt&para_community_id=#{data}"
  end

end
